package cn.com.open.errorquestion.provider;

import cn.com.open.errorquestion.model.AnswerQuestionLog;
import cn.com.open.errorquestion.util.StringUtil;
import org.apache.ibatis.jdbc.SQL;

public class AnswerQuestionLogProvider {

    private static String TABLE_NAME = "answer_question_log_";


    /**
     * 查询该提记录是否存在
     * @param answerData
     * @return
     */
    public String findOne(AnswerQuestionLog answerData){
        SQL sql = new SQL().SELECT("*").FROM(TABLE_NAME+answerData.getTableNumber());
        String organizationId = answerData.getOrganizationId();
        if(!StringUtil.isEmpty(organizationId)){
            sql.WHERE("organizationId = #{organizationId}");
        }
        String examineeId = answerData.getExamineeId();
        if(!StringUtil.isEmpty(examineeId)){
            sql.WHERE("examineeId = #{examineeId}");
        }
        String paperId = answerData.getPaperId();
        if(!StringUtil.isEmpty(paperId)){
            sql.WHERE("paperId = #{paperId}");
        }
        String questionId = answerData.getQuestionId();
        if(!StringUtil.isEmpty(questionId)){
            sql.WHERE("questionId = #{questionId}");
        }


        return sql.toString()+" limit 1";
    }


    public static void main(String[] args) {

        SQL sql = new SQL().SELECT("*").FROM(TABLE_NAME);
        sql.WHERE("limit 1");
        sql.WHERE("limit 1");
        SQL self = sql.getSelf();
        System.out.println(sql.toString()+" limit 1");
        System.out.println(self);
    }
}
